home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
681
/
term
/
source.lha
/
termScroll.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
14KB
|
633 lines
/*
** $Id: termScroll.c,v 1.4 92/05/09 15:54:33 olsen Sta Locker: olsen $
** $Revision: 1.4 $
** $Date: 92/05/09 15:54:33 $
**
** Support routines for optimized screen scrolling.
**
** Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
/* ScrollLineRectFill():
*
* Fill a rectangular portion of the window raster with the help
* of the scrolling information.
*/
VOID __regargs
ScrollLineRectFill(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
{
if(RPort -> BitMap -> Depth == 1)
RectFill(RPort,MinX,MinY,MaxX,MaxY);
else
{
if(MinX < MaxX)
{
/* Is there anything on the screen at all? */
if(ScrollLineFirst <= ScrollLineLast)
{
WORD ScrollLineMask = 0,ScrollLineLeft = 32767,ScrollLineRight = 0,Temp,i;
/* Determine screen colour mask. */
for(i = MinY >> 3 ; i <= MaxY >> 3 ; i++)
{
if(ScrollLines[i] . Shift)
{
if((Temp = ScrollLines[i] . Left << ScrollLines[i] . Shift) < ScrollLineLeft)
ScrollLineLeft = Temp;
if((Temp = (ScrollLines[i] . Right << ScrollLines[i] . Shift) - 1) > ScrollLineRight)
ScrollLineRight = Temp;
ScrollLineMask |= ScrollLines[i] . ColourMask;
}
}
/* Wrap the bits. */
ScrollLineMask &= (1 << Screen -> RastPort . BitMap -> Depth) - 1;
/* Did we get a sensible colour? */
if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
{
/* Determine new left margin. */
if(ScrollLineLeft > MinX)
MinX = ScrollLineLeft;
/* Determine new right margin. */
if(ScrollLineRight < MaxX)
MaxX = ScrollLineRight;
/* Determine new top line margin. */
if((Temp = ScrollLineFirst << 3) > MinY)
MinY = Temp;
/* Determine new bottom line margin. */
if((Temp = ((ScrollLineLast + 1) << 3) - 1) < MaxY)
MaxY = Temp;
/* Set the colour mask. */
if(!(Config . DisableBlinking & TERMINAL_FASTER))
SetWrMsk(RPort,ScrollLineMask);
/* And clear the raster. */
if(MinX < MaxX && MinY < MaxY)
{
if(MaxX == ScrollLineRight)
RectFill(RPort,MinX,MinY,MaxX + 4,MaxY);
else
RectFill(RPort,MinX,MinY,MaxX,MaxY);
}
}
}
}
}
}
/* ScrollLineRaster():
*
* Scroll the window raster with the help
* of the scrolling information.
*/
VOID __regargs
ScrollLineRaster(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
{
if(RPort -> BitMap -> Depth == 1)
ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
else
{
if(MinX < MaxX)
{
WORD ScrollLineMask;
/* Are we to scroll a line in horizontal direction? If so, use the
* colour mask of the current line.
*/
if(DeltaX)
{
if(ScrollLineMask = ScrollLines[CursorY] . ColourMask & ((1 << Screen -> RastPort . BitMap -> Depth) - 1))
{
/* Set the colour mask. */
if(!(Config . DisableBlinking & TERMINAL_FASTER))
SetWrMsk(RPort,ScrollLineMask);
/* And scroll the raster. */
ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
}
}
else
{
/* Any data on screen worth scrolling? */
if(ScrollLineFirst <= ScrollLineLast)
{
WORD Temp,First,Last,SaveMinY = MinY >> 3,SaveMaxY = MaxY >> 3,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
/* Reset colourmask. */
ScrollLineMask = 0;
/* Build both the colour mask and the margins. */
for(i = MinY >> 3 ; i <= MaxY >> 3 ; i++)
{
if(ScrollLines[i] . Shift)
{
if((Temp = ScrollLines[i] . Left << ScrollLines[i] . Shift) < ScrollLineLeft)
ScrollLineLeft = Temp;
if((Temp = (ScrollLines[i] . Right << ScrollLines[i] . Shift) - 1) > ScrollLineRight)
ScrollLineRight = Temp;
ScrollLineMask |= ScrollLines[i] . ColourMask;
}
}
/* Wrap the bits. */
ScrollLineMask &= (1 << Screen -> RastPort . BitMap -> Depth) - 1;
/* Sensible results? */
if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
{
/* Determine new left margin. */
if(ScrollLineLeft > MinX)
MinX = ScrollLineLeft;
/* Determine new right margin. */
if(ScrollLineRight < MaxX)
MaxX = ScrollLineRight;
/* Scroll down or up? */
if(DeltaY < 0)
{
/* So we are to scroll down, find the first
* blank line if any.
*/
if((Temp = ScrollLineFirst << 3) > MinY)
MinY = Temp;
/* Find the last blank lines if any. */
if((Temp = ((ScrollLineLast + 1) << 3) - DeltaY - 1) < MaxY)
MaxY = Temp;
/* Determine margins and the like... */
Last = (MaxY + 1) >> 3;
First = Last - ((MaxY - MinY + 8 + DeltaY) >> 3);
Temp = (-DeltaY) >> 3;
/* Move the scroll line info up. */
for(i = Last - 1 ; i >= First ; i--)
ScrollLines[i] = ScrollLines[i - Temp];
/* Clear the remaining lines. */
for(i = First - Temp ; i < First ; i++)
{
ScrollLines[i] . Left = 255;
ScrollLines[i] . Right = 0;
ScrollLines[i] . ColourMask = 0;
ScrollLines[i] . Shift = 0;
}
/* Is the first line we were working
* on the first line of the whole display?
* If so, update the line marker.
*/
if(!SaveMinY)
ScrollLineFirst += Temp;
/* Now take a look at the last line.
* If the last line we were working
* on is in fact the last line of the
* display, update the line marker.
*/
if(SaveMaxY == LastLine)
{
ScrollLineLast += Temp;
if(ScrollLineLast > LastLine)
ScrollLineLast = LastLine;
}
}
else
{
/* So we are to scroll up, find the last
* blank line if any.
*/
if((Temp = ((ScrollLineLast + 1) << 3) - 1) < MaxY)
MaxY = Temp;
/* Find the first blank lines if any. */
if((Temp = (ScrollLineFirst << 3) - DeltaY) > MinY)
MinY = Temp;
/* Determine margins and the like... */
First = MinY >> 3;
Last = ((MaxY - MinY + 8 - DeltaY) >> 3);
Temp = DeltaY >> 3;
/* Move the scroll line info down. */
for(i = First ; i < First + Last ; i++)
ScrollLines[i] = ScrollLines[i + Temp];
/* Clear the remaining lines. */
for(i = First + Last ; i < First + Last + Temp ; i++)
{
ScrollLines[i] . Left = 255;
ScrollLines[i] . Right = 0;
ScrollLines[i] . ColourMask = 0;
ScrollLines[i] . Shift = 0;
}
/* Decrease number of last line. */
if(SaveMaxY == LastLine)
{
if(ScrollLineLast > Temp)
ScrollLineLast -= Temp;
else
ScrollLineLast = 0;
}
/* Decrease number of first line. */
if(!SaveMinY)
{
if(ScrollLineFirst > Temp)
ScrollLineFirst -= Temp;
else
ScrollLineFirst = 0;
}
}
/* Adapt possible changes in the lines for first and last line. */
while(ScrollLineFirst < RasterHeight)
{
if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
ScrollLineFirst++;
else
break;
}
while(ScrollLineLast > 0)
{
if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
ScrollLineLast--;
else
break;
}
/* Set the colour mask. */
if(!(Config . DisableBlinking & TERMINAL_FASTER))
SetWrMsk(RPort,ScrollLineMask);
/* And scroll the raster. */
if(MinX < MaxX && MinY < MaxY)
{
if(MaxX == ScrollLineRight)
ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX + 4,MaxY);
else
ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
}
}
}
}
}
}
}
/* ScrollLineEraseScreen(BYTE Mode):
*
* Erase a part of the screen.
*/
VOID __regargs
ScrollLineEraseScreen(BYTE Mode)
{
if(RPort -> BitMap -> Depth > 1)
{
WORD i;
switch(Mode)
{
/* Erase from first line to current cursor line (inclusive). */
case 1: ScrollLineFirst = CursorY;
/* Reset the lines. */
for(i = 0 ; i < CursorY ; i++)
{
ScrollLines[i] . Left = 255;
ScrollLines[i] . Right = 0;
ScrollLines[i] . ColourMask = 0;
ScrollLines[i] . Shift = 0;
}
ScrollLines[CursorY] . Left = CursorX + 1;
if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
{
ScrollLines[CursorY] . Left = 255;
ScrollLines[CursorY] . Right = 0;
}
break;
/* Erase entire screen. */
case 2: for(i = 0 ; i < RasterHeight ; i++)
{
ScrollLines[i] . Left = 255;
ScrollLines[i] . Right = 0;
ScrollLines[i] . ColourMask = 0;
ScrollLines[i] . Shift = 0;
}
ScrollLineFirst = 255;
ScrollLineLast = 0;
break;
/* Erase from current cursor position to end of screen. */
default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
{
ScrollLines[i] . Left = 255;
ScrollLines[i] . Right = 0;
ScrollLines[i] . ColourMask = 0;
ScrollLines[i] . Shift = 0;
}
if(CursorX)
{
ScrollLines[CursorY] . Right = CursorX;
if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
{
ScrollLines[CursorY] . Left = 255;
ScrollLines[CursorY] . Right = 0;
}
}
else
{
ScrollLines[CursorY] . Left = 255;
ScrollLines[CursorY] . Right = 0;
}
/* Cleared the entire screen? */
if(CursorY)
ScrollLineLast = CursorY;
else
{
ScrollLineFirst = 255;
ScrollLineLast = 0;
}
break;
}
/* Adapt possible changes in the lines for first and last line. */
while(ScrollLineFirst < RasterHeight)
{
if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
ScrollLineFirst++;
else
break;
}
while(ScrollLineLast > 0)
{
if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
ScrollLineLast--;
else
break;
}
}
}
/* ScrollLineEraseLine(BYTE Mode):
*
* Erase parts of the current cursor line.
*/
VOID __regargs
ScrollLineEraseLine(BYTE Mode)
{
if(RPort -> BitMap -> Depth > 1)
{
switch(Mode)
{
/* Erase from left margin to current cursor position (inclusive). */
case 1: ScrollLines[CursorY] . Left = CursorX + 1;
break;
/* Erase entire line. */
case 2: ScrollLines[CursorY] . Left = 255;
ScrollLines[CursorY] . Right = 0;
break;
/* Erase from current cursor position towards end of line. */
default:if(CursorX)
ScrollLines[CursorY] . Right = CursorX;
else
{
ScrollLines[CursorY] . Left = 255;
ScrollLines[CursorY] . Right = 0;
}
break;
}
/* Adapt possible changes in the lines for first and last line. */
while(ScrollLineFirst < RasterHeight)
{
if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
ScrollLineFirst++;
else
break;
}
while(ScrollLineLast > 0)
{
if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
ScrollLineLast--;
else
break;
}
}
}
/* ScrollLineEraseCharacters(WORD Chars):
*
* Erase a number of characters in the current cursor line.
*/
VOID __regargs
ScrollLineEraseCharacters(WORD Chars)
{
if(RPort -> BitMap -> Depth > 1)
{
/* Any characters to erase? */
if(ScrollLines[CursorY] . Right)
ScrollLines[CursorY] . Right -= Chars;
}
}
/* ScrollLineShiftChar(WORD Size):
*
* Shift the characters following the current cursor position
* Size characters to the right.
*/
VOID __regargs
ScrollLineShiftChar(WORD Size)
{
if(RPort -> BitMap -> Depth > 1)
{
/* Any characters to scroll? */
if(ScrollLines[CursorY] . Right)
ScrollLines[CursorY] . Right += Size;
}
}
/* ScrollLinePutString(WORD Length):
*
* Update the line info according to the length of a string
* to be printed.
*/
VOID __regargs
ScrollLinePutString(WORD Length)
{
if(RPort -> BitMap -> Depth > 1)
{
BYTE Shift;
/* Which scale is the font we are currently using? */
if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
{
/* Valid length? */
if(CursorX + Length >= RasterWidth >> 1)
Length = (RasterWidth >> 1) - CursorX;
/* Double width (16 pixels wide). */
Shift = 4;
}
else
{
if(Config . FontScale == SCALE_HALF)
{
/* Valid length? */
if(CursorX + Length >= RasterWidth << 1)
Length = (RasterWidth << 1) - CursorX;
/* Half width (4 pixels wide). */
Shift = 2;
}
else
{
/* Valid length? */
if(CursorX + Length >= RasterWidth)
Length = RasterWidth - CursorX;
/* Normal width (8 pixels wide). */
Shift = 3;
}
}
/* Sensible value? */
if(Length > 0)
{
struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
/* Update line colour mask. */
Alias -> ColourMask |= (RPort -> FgPen|RPort -> BgPen);
/* Update font scale. */
Alias -> Shift = Shift;
/* Set write mask (will affect Text() since it is called
* after this routine has finished.
*/
if(!(Config . DisableBlinking & TERMINAL_FASTER))
SetWrMsk(RPort,Alias -> ColourMask);
/* Update right margin. */
if(CursorX < Alias -> Left)
Alias -> Left = CursorX;
/* Update left margin. */
if(CursorX + Length > Alias -> Right)
Alias -> Right = CursorX + Length;
/* Update topmost line. */
if(CursorY < ScrollLineFirst)
ScrollLineFirst = CursorY;
/* Update bottommost line. */
if(CursorY > ScrollLineLast)
ScrollLineLast = CursorY;
}
}
}